package com.example.snackfood.dao;

import com.example.snackfood.entity.Comments;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.Mapping;

import javax.annotation.Resource;

/**
 * @program: snackFood
 * @description:
 * @author: lydms
 * @create: 2023-11-23 13:20
 **/

@Component
public class SnackFoodCommentDao {

    @Resource
    private MongoTemplate mongoTemplate;

    /**
     * 成功加入评论
     * @param comments
     */
    public void add(Comments comments) {
        mongoTemplate.save(comments);
    }

    public Comments selectCommentById(Query query) {
       return mongoTemplate.findOne(query,Comments.class);
    }

    public void deleteComment(Query query) {
        mongoTemplate.remove(query,Comments.class);
    }
}
